/**************************************************************************
*   Copyright (C) 2009 Chernov Dmitry                                     *
*   diman4ik.chernov@gmail.com                                            *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/

#ifndef KORNERS_FIELD_RENDER
#define KORNERS_FIELD_RENDER

#include <QString>
#include <QSize>

class KSvgRenderer;
class KPixmapCache;
class QPixmap;


class KornersRender
{ 
public:
    /**
     * Returns one and the only instance of KornersRender
     */
    static KornersRender* self();

    bool hasBorderElement() const;

    /**
     * Sets render sizes for cells
     */
    void setCellSize(int nSize);

    /**
     * Loads new theme. Resets cache and puts new flashy rerendered
     * pixmaps there
     * @param themeName specifies theme name which is the part of the
     * theme's file path relative to $KDEDIR/share/apps/klines, for example
     * it might be "themes/default.desktop"
     */
    bool loadTheme( const QString& themeName );
    /**
     * @return pixmap for background painting.
     */
    QPixmap backgroundPixmap(const QSize& size) const;
    /**
     * @return pixmap of background tile (cell)
     */
    QPixmap backgroundTilePixmap() const;
    /**
     * @return pixmap for border surrounding the play field.
     * Will return an invalid QPixmap if no such element exists
     * in theme's svg file.
     * @see hasBorderElement
     */
    QPixmap backgroundBorderPixmap( const QSize& size ) const;
    /**
     * Tries to find pixmap with cacheName in cache.
     * If pixmap is not found in cache, this function will put it there
     * Pixmap is rendered according to current cellSize
     * If customSize is not passed, pixmap will be of (m_cellSize,m_cellSize) size
     *
     * @return rendered pixmap
     */
    QPixmap pixmapFromCache(const QString& svgName, const QSize& customSize = QSize()) const;
    /**
     * @return pixmap of player's cap
     */
    QPixmap playerCapPixmap( ) const;
    /**
     * @return pixmap of opponents's cap
     */
    QPixmap opponentCapPixmap( ) const;
    /**
     * @return pixmap of move highlighter
     */
    QPixmap moveHighlightPixmap() const;

private:
    /**
     *  This is the size of the scene's cell.
     *  All rendered pixmaps (except background) will have this size
     */
    int m_cellSize;

    
    KornersRender();

    /**
     * Name of currently loaded theme
     */
    QString m_currentTheme;


    KSvgRenderer *m_renderer;
    KPixmapCache *m_cache;
};

#endif